package net.xdclass.strategy;


import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;

import java.util.Collection;

public class CustomTablePreciseShardingAlgorithm implements PreciseShardingAlgorithm<String> {

    @Override
    public String doSharding(Collection<String> collection, PreciseShardingValue<String> preciseShardingValue) {
        //获取逻辑表
        String targetName = collection.iterator().next();

        //短链码
        String value = preciseShardingValue.getValue();

        //获取短链码最后一位
        String codeSuffix = value.substring(value.length() - 1);

        //拼接真实表
        return targetName + "_" + codeSuffix;
    }
}
